package xq.pug.common.exception.errorType;

import lombok.Getter;

/**
 * @author RenGaoshuai
 * @date 2023/7/6 14:01
 * @description
 */
@Getter
public enum SystemErrorType implements ErrorType {
    SYSTEM_ERROR(-1, "系统异常"),
    SYSTEM_BUSY(1, "系统繁忙,请稍候再试"),

    GATEWAY_NOT_FOUND_SERVICE(10404, "服务未找到"),
    GATEWAY_ERROR(10500, "网关异常"),
    GATEWAY_CONNECT_TIME_OUT(10002, "网关超时"),

    ARGUMENT_NOT_VALID(20000, "请求参数校验不通过"),
    INVALID_TOKEN(20001, "无效token"),
    BLANK_TOKEN(20002, "token为空"),
    TIMEOUT_TOKEN(20003, "token超时"),
    UPLOAD_FILE_SIZE_LIMIT(20010, "上传文件大小超过限制"),

    DUPLICATE_PRIMARY_KEY(30000, "唯一键冲突"),
    NULL_POINTER(30001, "空指针异常"),
    CLASS_CAST(30002, "类型转化异常"),
    UNKNOW_EXCEPTiON(-404, "未知异常");

    /**
     * 错误类型码
     */
    private Integer code;
    /**
     * 错误类型描述信息
     */
    private String message;

    SystemErrorType(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static SystemErrorType getInstance(Integer code) {
        SystemErrorType[] values = SystemErrorType.values();
        for (SystemErrorType systemErrorType : values) {
            if (code == systemErrorType.code) {
                return systemErrorType;
            }
        }
        return UNKNOW_EXCEPTiON;
    }

    public static String getMesg(Integer code) {
        SystemErrorType exceptionEnum = getInstance(code);
        if (exceptionEnum == null) {
            return UNKNOW_EXCEPTiON.getMessage();
        }
        return exceptionEnum.getMessage();
    }

}
